package com.课上案例练习.网络编程.版本四群聊.接收的线程;


import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import static com.课上案例练习.网络编程.版本四群聊.Client.socketArrayList;

public class ServerThreadinput extends Thread {
    private Socket socket;

    public ServerThreadinput(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try{

        while (true){
            DataInputStream  dataInputStream = new DataInputStream(socket.getInputStream());
            String s = dataInputStream.readUTF();//
            for (Socket socket1 : socketArrayList) {
                if(socket1!=socket){
                    DataOutputStream dataOutputStream = new DataOutputStream(socket1.getOutputStream());
                    dataOutputStream.writeUTF(s);
                }
            }
        }
        }catch (IOException e)
             {
                 throw new RuntimeException(e);
             }



        }
    }